package com.skymxc.wandroidtodo.page.register;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;

import com.skymxc.wandroidtodo.R;
import com.skymxc.wandroidtodo.databinding.ActivityRegisterBinding;
import com.skymxc.wandroidtodo.page.base.BaseActivity;
import com.skymxc.wandroidtodo.page.main.MainActivity;

/**
 * <p>
 *
 * </p>
 *
 * @author 孟祥超
 * <p>
 * date: 2021/12/2  9:50 下午
 */
public class RegisterActivity extends BaseActivity<RegisterPresenter> implements RegisterContact.RegisterView , View.OnClickListener {
    private ActivityRegisterBinding mBinding;



    @Override
    protected void initView() {
        super.initView();
        mBinding = ActivityRegisterBinding.inflate(getLayoutInflater());
        setContentView(mBinding.getRoot());
        mBinding.registerBtnRegister.setOnClickListener(this);
    }

    @Override
    protected RegisterPresenter initPresenter() {
        return new RegisterPresenter(getApplication());
    }

    @Override
    public void registerSuccess() {
        hideProgress();
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.register_btn_register:
                String username = mBinding.registerEtUsername.getText().toString();
                if (TextUtils.isEmpty(username)){
                    showConfirm("请输入用户名");
                    return;
                }
                String password = mBinding.registerEtPassword.getText().toString();
                if (TextUtils.isEmpty(password)){
                    showConfirm("请输入密码");
                    return;
                }
                String repassword = mBinding.registerEtRepassword.getText().toString();
                if (TextUtils.isEmpty(repassword)){
                    showConfirm("请重复密码");
                    return;
                }
                if (!repassword.equals(password)){
                    showConfirm("两次密码输入不一致");
                    return;
                }
                mPresenter.register(username,password,repassword);
                break;
        }
    }
}
